#include <iostream>
#include <regex>
#include <string>
#include <sstream>

int main() {
    std::string content = "`define ENABLE_FEATURE\n`define DATA_WIDTH 8\n`define CALC_FUNC(x) ((x)*2+1)\n";
    
    std::regex defineRegex("`define\\s+(\\w+)(?:\\s*\\(([^)]*)\\))?(?:\\s+(.+))?");
    std::smatch matches;
    
    std::istringstream iss(content);
    std::string line;
    int count = 0;
    
    while (std::getline(iss, line)) {
        if (std::regex_search(line, matches, defineRegex)) {
            count++;
            std::string macroName = matches[1].str();
            std::string params = matches[2].str();
            std::string macroValue = matches[3].str();
            
            // 移除前后空格
            macroValue.erase(0, macroValue.find_first_not_of(" \t"));
            macroValue.erase(macroValue.find_last_not_of(" \t") + 1);
            
            std::cout << "Found macro " << count << ": " << macroName;
            if (!params.empty()) {
                std::cout << "(" << params << ")";
            }
            if (!macroValue.empty()) {
                std::cout << " = " << macroValue;
            }
            std::cout << std::endl;
        }
    }
    
    std::cout << "Total macros found: " << count << std::endl;
    return 0;
}